package com.tj.bo.user.server.dao.impl;

import com.fqgj.common.base.AbstractBaseMapper;
import com.fqgj.common.datasource.DataSource;
import com.tj.bo.user.server.dao.UserAccessDao;
import com.tj.bo.user.server.entity.UserAccessEntity;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * User: anonymous
 * Date: 2020-06-10
 * Time: 15:40:06.929
 */
@DataSource("dataSourceUser")
@Repository
public class UserAccessDaoImpl extends AbstractBaseMapper<UserAccessEntity> implements UserAccessDao {

    @Override
    public UserAccessEntity selectUserAccessByUserCode(String userCode) {
        Map<String, Object> params = new HashMap<>();
        params.put("userCode", userCode);
        return getSqlSession().selectOne(this.getStatement("selectUserAccessByUserCode"), params);
    }

    @Override
    public UserAccessEntity selectUserAccessByToken(String realToken) {
        Map<String, Object> params = new HashMap<>();
        params.put("token", realToken);
        params.put("realFlag", 1);
        return getSqlSession().selectOne(this.getStatement("selectUserAccessByToken"), params);
    }

    @Override
    public UserAccessEntity selectUserAccessByLoginNumber(String appCode, Integer realFlag, String loginNumber) {
        Map<String, Object> params = new HashMap<>();
        params.put("appCode", appCode);
        params.put("realFlag", realFlag);
        params.put("loginNumber", loginNumber);
        return getSqlSession().selectOne(this.getStatement("selectUserAccessByLoginNumber"), params);
    }

    @Override
    public UserAccessEntity selectUserAccessByLoginNumberAndType(String appCode, Integer realFlag, String loginNumber, Integer registerType) {
        Map<String, Object> params = new HashMap<>();
        params.put("appCode", appCode);
        params.put("realFlag", realFlag);
        params.put("loginNumber", loginNumber);
        params.put("registerType", registerType);
        return getSqlSession().selectOne(this.getStatement("selectUserAccessByLoginNumberAndType"), params);
    }

    @Override
    public UserAccessEntity selectUserAccessByAppCodeAndEmail(String appCode, Integer realFlag, String email) {
        Map<String, Object> params = new HashMap<>();
        params.put("appCode", appCode);
        params.put("realFlag", realFlag);
        params.put("email", email);
        return getSqlSession().selectOne(this.getStatement("selectUserAccessByAppCodeAndEmail"), params);
    }

    @Override
    public UserAccessEntity selectUserAccessByAppCodeAndOpenId(String appCode, Integer realFlag, Integer type, String openId) {
        Map<String, Object> params = new HashMap<>();
        params.put("appCode", appCode);
        params.put("realFlag", realFlag);
        params.put("registerType", type);
        params.put("openId", openId);
        return getSqlSession().selectOne(this.getStatement("selectUserAccessByAppCodeAndOpenId"), params);
    }

    @Override
    public UserAccessEntity selectUserAccessByCustomerCode(String appCode, Integer realFlag, String customerCode) {
        Map<String, Object> params = new HashMap<>();
        params.put("appCode", appCode);
        params.put("realFlag", realFlag);
        params.put("customerCode", customerCode);
        return getSqlSession().selectOne(this.getStatement("selectUserAccessByCustomerCode"), params);
    }

    @Override
    public UserAccessEntity selectUserAccessByEmailPassword(String appCode, Integer realFlag, String email, String password) {
        Map<String, Object> params = new HashMap<>();
        params.put("appCode", appCode);
        params.put("realFlag", realFlag);
        params.put("email", email);
        params.put("passWord", password);
        return getSqlSession().selectOne(this.getStatement("selectUserAccessByEmailPassword"), params);
    }

    @Override
    public List<UserAccessEntity> selectUserAccessByDeviceId(String appCode, String deviceId, String channel) {
        Map<String, Object> params = new HashMap<>();
        params.put("appCode", appCode);
        params.put("deviceId", deviceId);
        params.put("channel", channel);
        return getSqlSession().selectList(this.getStatement("selectUserAccessByDeviceId"), params);
    }

    @Override
    public List<UserAccessEntity> selectUserAccessForAllRealUser() {
        return getSqlSession().selectList(this.getStatement("selectUserAccessForAllRealUser"));
    }

    @Override
    public List<UserAccessEntity> selectRealUserAccessGroupByDeviceId(Integer deviceIdNum) {
        Map<String, Object> params = new HashMap<>();
        params.put("deviceIdNum", deviceIdNum);
        return getSqlSession().selectList(this.getStatement("selectRealUserAccessGroupByDeviceId"), params);
    }

    @Override
    public List<UserAccessEntity> selectUserAccessInfoByDeviceId(String deviceId) {
        Map<String, Object> params = new HashMap<>();
        params.put("deviceId", deviceId);
        return getSqlSession().selectList(this.getStatement("selectUserAccessInfoByDeviceId"), params);
    }
}